package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicXlbOauth2token;
import cn.stylefeng.guns.modular.basic.mapper.BasicXlbOauth2tokenMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicXlbOauth2tokenParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicXlbOauth2tokenResult;
import  cn.stylefeng.guns.modular.basic.service.BasicXlbOauth2tokenService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 新零帮oauth2授权表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2024-01-17
 */
@Service
public class BasicXlbOauth2tokenServiceImpl extends ServiceImpl<BasicXlbOauth2tokenMapper, BasicXlbOauth2token> implements BasicXlbOauth2tokenService {

    @Override
    public void add(BasicXlbOauth2tokenParam param){
        BasicXlbOauth2token entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicXlbOauth2tokenParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicXlbOauth2tokenParam param){
        BasicXlbOauth2token oldEntity = getOldEntity(param);
        BasicXlbOauth2token newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicXlbOauth2tokenResult findBySpec(BasicXlbOauth2tokenParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<BasicXlbOauth2tokenResult> findListBySpec(BasicXlbOauth2tokenParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicXlbOauth2tokenParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicXlbOauth2tokenParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicXlbOauth2token getOldEntity(BasicXlbOauth2tokenParam param) {
        return this.getById(getKey(param));
    }

    private BasicXlbOauth2token getEntity(BasicXlbOauth2tokenParam param) {
        BasicXlbOauth2token entity = new BasicXlbOauth2token();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
